package com.lx.service.impl;

import com.lx.dao.TradeDao;
import com.lx.dao.impl.TradeDaoImpl;
import com.lx.entity.BankCard;

import com.lx.service.TradeService;
import com.lx.uitl.ConnUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @title: TradeServiceImpl
 * @projectName bankManage
 * @description: TODO
 * @author: yuanChu
 * @date: 2022/5/6  8:34
 */
public class TradeServiceImpl implements TradeService {
    TradeDao tradeDao = new TradeDaoImpl();

    @Override
    public Boolean saveMoney(Double money, String cardId) {
        Integer i = null;
        try {
            i = tradeDao.saveMoney(money, cardId);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            ConnUtil.closeConnection();
        }
        if(i != 0&& i !=null){
            return true;
        }
        return false;
    }

    @Override
    public Boolean takeMoney(Double money, String cardId) {
        Integer i = null;
        try {
            i = tradeDao.takeMoney(money, cardId);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            ConnUtil.closeConnection();
        }
        if(i != 0&& i !=null){
            return true;
        }
        return false;
    }

    @Override
    public List<BankCard> findBankCardByPhone(String phone) {
        List<BankCard> list = null;
        try {
            list = tradeDao.findBankCardByPhone(phone);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            ConnUtil.closeConnection();
        }
        return list;
    }
}
